#include<iostream>
#include<string>
#include<jsoncpp/json/json.h>
#include<memory>
#include<sstream>

int main()
{
    //反序列化
    std::string json_string = "{\"name\":\"zhangsan\",\"age\":30,\"city\":\"北京\"}";
    //反序列化起手Json::Value
    Json::Value root;
    Json::Reader reader;

    bool ok = reader.parse(json_string,root);
    (void)ok;
    
    //把序列化字符串，反序列化到Json::Value里面
    std::string name = root["name"].asString();
    int age = root["age"].asInt();
    std::string city = root["city"].asString();
    std::cout<<name<<std::endl;
    std::cout<<age<<std::endl;
    std::cout<<city<<std::endl;


    //序列化
    // Json::Value root;
    // root["name"] = "zhansan";
    // root["sex"] = "nan";
    // root["age"] = 18;

    // Json::StreamWriterBuilder sbuilder;
    // std::unique_ptr<Json::StreamWriter> writer(sbuilder.newStreamWriter());
    // std::stringstream ss;
    // writer->write(root,&ss);
    // std::string s = ss.str();
    // std::cout<<s<<std::endl;

    //Json::FastWriter writer;//求掉换行符
    // Json::StyledWriter writer;//进行换行设置，可读性比较好
    // std::string s = writer.write(root);
    // std::cout<<s<<std::endl;

    // std::string s  = root.toStyledString();
    //std::cout<<s<<std::endl;

}